"""
# -*- coding: utf-8 -*-
# @Time    : 2023/5/31 16:52
# @Author  : 王摇摆
# @FileName: Visual.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
人工手动生成两条直线来对已知的数据点进行拟合
"""
import numpy as np
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['microsoft yahei']  # 选择一个本地的支持中文的字体
fig, axs = plt.subplots(2, 1)
ax1 = axs[0]
ax2 = axs[1]
ax1.set_facecolor('#f8f9fa')
ax2.set_facecolor('#f8f9fa')

W = np.array([2000])
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([1598, 3898, 6220, 7799, 10510])

x1 = X[:][:, 0]
y1 = y
ax1.scatter(x1, y1, marker='o', s=20, c='#e63946')
x2 = np.linspace(0, 6, 100)
y2 = W[0] * x2
ax1.plot(x2, y2, '#457b9d', label='直线A')
x3 = np.linspace(0, 6, 100)
y3 = 1500 * x3 + 1200
ax2.scatter(x1, y1, marker='o', s=20, c='#e63946')
ax2.plot(x3, y3, '#457b9d', label='直线B')
for i in range(len(x1)):
    ax1.plot(np.linspace(x1[i], x1[i], 100), np.linspace(y1[i], W[0] * x1[i], 100), '#219ebc', linestyle='--')
    ax2.plot(np.linspace(x1[i], x1[i], 100), np.linspace(y1[i], 1500 * x1[i] + 1200, 100), '#219ebc', linestyle='--')
ax1.set_title('工作年限与平均工资关系表', color='#264653')
ax1.tick_params(labelcolor='#264653')
ax1.legend(loc="upper left")
ax2.tick_params(labelcolor='#264653')
ax2.legend(loc="upper left")
plt.ylim(0, 13000)
plt.show()
